package client;

public class Timer extends Thread {

	public static long SAFETY_MARGIN = 50;

	private long startTime;
	private long endTime;
	private long deadline;
	private boolean timeUp;

	public Timer(long d) {
		deadline = d;
	}

	public void run() {
		long d = deadline;
		timeUp = false;
		startTime = System.currentTimeMillis();
		endTime = startTime + deadline;
		while (d > SAFETY_MARGIN) {
			try {
				sleep(d / 2);
			}
			catch (InterruptedException e) {
				break;
			}
			d = endTime - System.currentTimeMillis();
		}
		timeUp = true;
	}

	public boolean isTimeUp() {
		return timeUp;
	}

}
